<?
header("Content-type: application/vnd.ms-excel");
//header("Content-disposition: csv" . date("Y-m-d") . ".xls");

$extype = "csv";
$filename = "SENARAI_OUTING_TAHUN_BY_ASRAMA_$date_to_find";
//header( "Content-disposition: filename=$act.$extype");
header( "Content-disposition: filename=$filename.$extype");

$glue = '';
if ($extype == 'xls') $glue = "\t"; 
if ($extype == 'csv') $glue = ',';
 
//$flds = array('staff_name','bil_pelawat');
$arr = array("Nama Pelajar","No Matrik", "Asrama", "Tarikh Keluar","Waktu Keluar","Tarikh Masuk","Waktu Masuk");
$csv_output = join("$glue",$arr) . "\n"; 

$num = pg_num_rows($students);

for ($i=0;$i<$num;$i++) {
	$dat = pg_fetch_object($students,$i);
	$waktu_keluar = "$dat->jam:$dat->minit";
	$waktu_masuk = "$dat->jam_masuk:$dat->minit_masuk";
	if ($dat->jam == '') $waktu_keluar = '';
	if ($dat->jam_masuk == '') $waktu_masuk = '';
	
	$arr = array();
	$arr[] = $dat->name;
	$arr[] = $dat->nomatrik;
	$arr[] = $dat->room_no;
	$arr[] = $dat->tarikh_keluar;
	$arr[] = $waktu_keluar;
	$arr[] = $dat->tarikh_masuk;
	$arr[] = $waktu_masuk;
		
	$csv_output .= join("$glue",$arr) . "\n";
}

print $csv_output;
exit; 
?>